package logic

import (
	"context"
	"meituan-waimai/meituanrpc/meituanrpc"

	"meituan-waimai/api/internal/svc"
	"meituan-waimai/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CouponReceiveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCouponReceiveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CouponReceiveLogic {
	return &CouponReceiveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CouponReceiveLogic) CouponReceive(req *types.CouponReceiveRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	receive, err := l.svcCtx.MeiTuanRpc.CouponReceive(l.ctx, &meituanrpc.CouponReceiveRequest{
		CouponId: req.CouponId,
		UserId:   req.UserId,
	})
	if err != nil {
		return &types.Response{
			Code: -1,
			Msg:  "领取优惠券失败",
			Data: err.Error(),
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "领取优惠券成功",
		Data: receive,
	}, nil
}
